package org.wendu.wdoa.security.role.dao;

import org.apache.ibatis.annotations.*;
import org.wendu.wdoa.security.home.model.Fun;
import org.wendu.wdoa.security.role.dto.RoleQueryDto;
import org.wendu.wdoa.security.role.model.Role;


import java.util.List;

@Mapper // 说明该对象接收spring管理，并且是一个持久化组件
public interface RoleDao {



    List<Role> findRolePage(RoleQueryDto dto);

    @Select("select p.f_id p_id, p.f_name p_name, c.f_id, c.f_name from t_fun p join t_fun c on c.f_pid = p.f_id where c.f_ismenu = 1 order by p.f_id, c.f_id")
    List<Fun> findFunList();

    @Insert("insert into t_role(ro_id, ro_name) value (#{ro_id}, #{ro_name})")
    void addRole(RoleQueryDto roleQueryDto);

    @Select("select ifnull(max(convert(ro_id,unsigned)),0)+1 from t_role")
    String findNewId();

    @Select("select f_id from t_rf where ro_id = #{ro_id}")
    List<Integer> findRoleFunIds(String ro_id);

    @Delete("delete from t_rf where ro_id = #{ro_id}")
    void deleteRoleFuns(String ro_id);

    @Select("select count(u_id) from t_ur where ro_id = #{ro_id}")
    boolean findExistsUser(Integer ro_id);

    void insertRoleFuns(@Param("ro_id") String ro_id,@Param("f_ids") Integer[] f_ids);

    @Select("select count(f_id) from t_rf where ro_id =#{ro_id}")
    boolean findExistFun(Integer ro_id);

    @Delete("delete from t_role where ro_id = #{ro_id}")
    void deleteRoleName(Integer ro_id);
}
